package com.example.sprintbootarithmetic.DataStructure.recursion;

public class Queue8 {
    static int max = 8;
    static int[] array = new int[max];
    static int count = 0;

    public static void main(String[] args) {
        yue(0);
        System.out.println();
        System.out.printf("����%d�нⷨ", count);
    }

    public static void yue(int n) {
        if (n == max) {
            print();
            return;
        }
        for (int i = 0; i < array.length; i++) {
            //��0��0��ʼ
            array[n] = i;
            //�Ƿ�����ʺ�����
            if (repetition(n)) {
                yue(n + 1);
            }
        }
    }

    private static boolean repetition(int n) {
        for (int i = 0; i < n; i++) {
            //�жϵ�ǰ�к�б�����Ƿ��лʺ�
            if (array[i] == array[n] || Math.abs(array[i] - array[n]) == Math.abs(i - n)) {
                return false;
            }
        }
        return true;
    }

    public static void print() {
        count++;
        System.out.println();
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + "\t");
        }
    }
}
